<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Http\Resources\OrderResource;
use App\Models\Order;
use Illuminate\Http\Request;

class OrderController extends Controller
{

    public function index()
    {
        $orders = OrderResource::collection(Order::orderByDesc('id')->paginate(10));
        return $orders;
    }

    public function show(Order $order)
    {
        return $order;
    }

    public function update(Request $request, Order $order)
    {
        $order->update($request->input());
        return $this->message('处理成功');
    }

    /**
     * 在途订单
     * @return mixed
     */
    public function process()
    {
        $orders = Order::where('status', '0')->paginate(5);
        return $orders;
    }

    /**
     * 归档订单
     */
    public function archive()
    {
        $orders = Order::whereIn('status', ['-1', '1'])->paginate(5);
        return $orders;
    }

    public function store(Request $request, Order $order)
    {
        $request->validate([
            'name' => ['required'],
            'mobile' => ['required']
        ]);
        $order = Order::create($request->input());
//发送短信预约
//        CodeService::send($order);

        return $this->message('预约成功');
    }
}
